package chloroform.exec

import chloroform.{InstanceExecutorContext, InstanceExecutor}
import genstream.ServiceFactory

/**
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: 16.4.11
 * Time: 12:12
 * To change this template use File | Settings | File Templates.
 */

object ServiceFactoryExecutor extends InstanceExecutor {
  def execute(instance: Any, context: InstanceExecutorContext) = {

    if (instance.isInstanceOf[ServiceFactory[_]]) {

      val serviceInstance = instance.asInstanceOf[ServiceFactory[_]].newInstance
      val serviceExecutorChain = context.chain.createAnotherChain(serviceInstance)
      serviceExecutorChain.execute

    } else
      context.chain.execute
  }
}